package core.behaviors;

import core.Actor;
import core.CoreTypes;
import core.units.Unit;

public class BounceOff extends Behavior {

	public BounceOff() {
		super(CoreTypes.FRAMEBOUNCE);
	}
	
	public void step(Actor... actors)
	{
		super.step();
		try {
			Unit ball = (Unit) actors[0];
			if (ball.getLeft() < -1 || ball.getRight() > 1)
	        {
	            ball.getVelocity().setDirection(180 - ball.getVelocity().getDirection());
	        }
	        // bounce off the top or bottom walls
	        if (ball.getTop() > 1 || ball.getBottom() < -1)
	        {
	            ball.getVelocity().setDirection(-ball.getVelocity().getDirection());
	        }
		} catch (Exception e) {
			return; // do nothing;
		}
	}

}
